package tests.mbsl.util;

import mbsl.util.ReleaseNameParser;
import mbsl.util.ReleaseNameParser.ReleaseData;

import org.junit.Test;

import junit.framework.TestCase;

public class ReleaseNameParserTester extends TestCase {
	@Test
	public void testIsRelease() {
		String[] name = new String[] {
				"Brothers.in.Arms.Hells.Highway-RELOADED", 	// Normal dots and dash
				"CALL.OF.DUTY.2-DEViANCE", 					// Same, but with caps
				"Call_Of_Duty_4-Razor1911", 				// Same, but with _ instead of .
				"Mas-zzz-ER", 								// Same, but with - in the name
				"Cake is good-omgz", 						// Same, but with whitespace instead of . or _
				"XXXI-EXA",									// Same, but with only one word
				"R-R",										// Same, but with really short parts
				"Elvis", 									// Not a release (No dash)
				"Cake-", 									// Not a release (No text after the dash)
				"Cake - Sake", 								// Not a release (Whitespace after the dash)
				".a-z",										// Not a release (Doesn't start with a letter)
				"",											// Not a release (Cake, you know)
				"Oil-Based Fuels",							// Not a release (Whitespace after the dash)
		};
		boolean[] truth = new boolean[] {
				true,
				true,
				true,
				true,
				true,
				true,
				true,
				false,
				false,
				false,
				false,
				false,
				false
		};
		
		for (int i = 0; i < name.length; i++)
			assertTrue(ReleaseNameParser.isRelease(name[i]) == truth[i]);
	}
	@Test
	public void testParse() {
		String[][] names = new String[][] {
				{"Brothers.in.Arms.Hells.Highway-RELOADED", 	"Brothers in Arms Hells Highway",		"RELOADED"}, // Straight forward
				{"CALL.OF.DUTY.2-DEViANCE", 					"Call of Duty 2", 						"DEViANCE"}, // Capitalisation
				{"Call_Of_Duty_4-Razor1911", 					"Call of Duty 4", 						"Razor1911"}, // Underscores
				{"XIII-FLT", 									"XIII", 								"FLT"}, // Roman numerals
				{"The.Elder.Scrolls.IV.Oblivion-RELOADED",		"The Elder Scrolls IV Oblivion", 		"RELOADED"}, // More Roman numerals
				{"THE.THE.THE-THE",								"The the the", 							"THE"}, // Capitalisation
				{"",											"",										null}, // Void
				{"-",											"-", 									null}, // Only a dash
				{"Cake-",										"Cake-",								null}, // Ends with a dash
				{"a",											"A",									null}, // One letter, and caps
				{"i_had_a_dream_where_i_was_a_monkey",			"I Had a Dream Where I Was a Monkey",	null} // Capitalisation
		};
		
		for (String[] strings : names) {
			ReleaseData d = ReleaseNameParser.parse(strings[0]);
			
			assertEquals(d.getTitle(), strings[1]);
			
			if (strings[2] == null)
				assertNull(d.getGroupName());
			else
				assertEquals(d.getGroupName(), strings[2]);
		}
	}
	@Test
	public void testGroupName() {
		String[][] names = new String[][] {
				{"Elvis-",	null}
		};
		for (String[] strings : names)
			if (strings[1] == null)
				assertNull(ReleaseNameParser.parse(strings[0]).getGroupName());
			else
				assertEquals(ReleaseNameParser.parse(strings[0]).getGroupName(), strings[1]);
	}
}
